home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / FileBrowser / Controller.m < prev    next >
Text File  |  1995-06-12  |  2KB  |  133 lines

  1.  
  2. #import "Controller.h"
  3.  
  4. /* Global Variables  */
  5.  
  6.     char    directoryName[MAXPATHLEN + 1] = "/";
  7.     BOOL    first=YES;
  8.  
  9. /* c subroutines  */
  10.  
  11. static BOOL isOK(const char *s)
  12. {
  13.     return (!s[0] || s[0] == '.') ? NO : YES;
  14. }
  15.  
  16.  
  17. @implementation Controller
  18.  
  19. - init
  20. {
  21.     [super init];
  22.     return self;
  23. }
  24.  
  25. - appDidInit:sender
  26. {
  27.     [browserView setPath:"/"];
  28.     [browserView setTitle:directoryName ofColumn:0];
  29.     [browserView loadColumnZero];
  30.     [browserView setTarget:self];
  31.     [browserView setAction:@selector(changeFile:)];
  32.     [browserView setDoubleAction:@selector(selectFile:)];
  33.     return self;
  34. }
  35.  
  36. - changeFile:sender
  37. {
  38.     const char    *file;
  39.     char        dummy[MAXPATHLEN + 1];
  40.     char        *path;
  41.     char          pathfile[MAXPATHLEN + 1];
  42.     id            cell;
  43.     
  44.     cell = [[sender matrixInColumn:[sender lastColumn]] selectedCell];
  45.     
  46.     path = [sender getPath:dummy toColumn:[sender lastColumn]];
  47.     
  48.     strcpy(pathfile, path);
  49.     strcat(pathfile, "/");
  50.  
  51.     file = [cell stringValue];
  52.  
  53.     if (file)
  54.     {
  55.         strcat(pathfile, file);    
  56.     }
  57.  
  58.     [selTextView setStringValue:""];
  59.     [curTextView setStringValue:pathfile];
  60.     return self;
  61. }
  62.  
  63. - selectFile:sender
  64. {
  65.     const char    *file;
  66.     char        dummy[MAXPATHLEN + 1];
  67.     char        *path;
  68.     char          pathfile[MAXPATHLEN + 1];
  69.     id            cell;
  70.     
  71.     cell = [[sender matrixInColumn:[sender lastColumn]] selectedCell];
  72.     
  73.     path = [sender getPath:dummy toColumn:[sender lastColumn]];
  74.     
  75.     strcpy(pathfile, path);
  76.     strcat(pathfile, "/");
  77.  
  78.     file = [cell stringValue];
  79.  
  80.     if (file)
  81.     {
  82.         strcat(pathfile, file);    
  83.     }
  84.  
  85.     [curTextView setStringValue:""];
  86.     [selTextView setStringValue:pathfile];
  87.     return self;
  88. }
  89.  
  90.  
  91. - (int)browser:sender fillMatrix:matrix inColumn:(int)column
  92. {
  93.     struct     stat buf;
  94.     DIR        *dirp;
  95.     struct     direct *dp;
  96.     int        count = 0;
  97.     char     file[MAXPATHLEN + 1], *test;
  98.     
  99.     test = [sender getPath:file toColumn:column];
  100.             
  101.     if (!first)
  102.     {
  103.         strcpy(directoryName, file);
  104.     }
  105.     else
  106.     {
  107.         first = NO;
  108.     }
  109.     
  110.     dirp = opendir(directoryName);
  111.  
  112.     for (dp = readdir(dirp); dp !=NULL; dp = readdir(dirp))
  113.         if(isOK(dp->d_name))
  114.         {
  115.             [matrix renewRows:count+1 cols:1];
  116.             [[matrix cellAt:count :0] setStringValue:dp->d_name];
  117.             [[matrix cellAt:count :0] setLoaded:YES];
  118.  
  119.             strcpy(file, directoryName);
  120.             strcat(file, "/");
  121.             strcat(file, dp->d_name);
  122.             stat(file, &buf);
  123.             if ((buf.st_mode & S_IFMT) != S_IFDIR)
  124.                 [[matrix cellAt:count :0] setLeaf:YES];
  125.             count++;
  126.         }
  127.         closedir(dirp);
  128.  
  129.         return count;
  130. }
  131.  
  132. @end
  133.